<template>
	<view class="topbox">
		<view class="cont">
			<view class="dzbox" @click="selectsite">
				<view class="leftbox" v-if="show">
					<view class="namebox">
						<text class="name">{{siteobj.name}}</text>
						<text>{{siteobj.phone}}</text>
						<text class="moren" v-if="siteobj.is_default==1">默认</text>
					</view>
					<view class="site">
						{{siteobj.address}}
					</view>
				</view>
				<view class="" v-else>
					快去设置一个地址吧
				</view>
				<view class="angle"></view>
			</view>
			<view class="hrs"></view>
			<view class="boxs">
				<view class="spxx">
					<image :src="obj.img" mode=""></image>
					<view class="rightbox">
						<view class="namebox">
							<view class="name">
								{{obj.name}}
							</view>
							<view class="shulian">
								×{{obj.num}}
							</view>
						</view>
						<!-- <view class="centerbox">
							{{obj.commodity_attr_ids}}
						</view> -->
						<view class="jifenbox">
							<text class="num">{{obj.integral*obj.num}}</text>
							<text>积分</text>
						</view>
					</view>
				</view>
				<view class="hr"></view>
			</view>
			<view class="hrs"></view>

			<view class="hrs"></view>
			<view class="heji">
				<text class="hjname"> 商品合计</text>
				<text>{{obj.integral*obj.num}}积分</text>
			</view>
			<!-- <view class="heji">
				<text class="hjname"> 运费</text>
				<text>￥0.00</text>
			</view> -->
			<view class="heji">
				<text class="hjname"> 订单备注</text>
				<textarea value="" placeholder="选填,请输入买家备注" v-model="remarks" />
			</view>
		</view>
		<view class="tijiaobox">
			<view class="fukuan">
				还需支付：<text>{{obj.integral*obj.num}}</text>积分
			</view>
			<view class="tijiao" @click="pay">
				提交订单
			</view>
		</view>
	</view>
</template>

<script>
	import {
		settlementsubmit,
		exchange,
		exchangesubmit
	} from "../../api/api/index.js"
	export default {
		data() {
			return {
				jkarr: [],
				siteobj: {},
				list: [],
				identity: 0,
				obj: {},
				xzcoupons: {},
				show: true,
				// 总价
				allprice: "",
				remarks: "",
				id: 0,
				value: 1,
				integral: 0
			}
		},
		methods: {
			cope(v) {
				let a = v.toString()
				uni.setClipboardData({
					data: a,
					success: function() {},
					fail() {
						console.log("失败")
					}
				});
			},
			// 选择地址
			selectsite() {
				this.jumpLink({
					link: "/pages/selectsite/index"
				})
			},
			// 优惠券
			mycoupon() {
				this.jumpLink({
					link: "/pages/my_coupon/index"
				})
			},
			pay() {
				if (this.obj.num * this.obj.integral < this.integral) {
					let data = {
						commodity_id: this.obj.id,
						address_id: this.siteobj.id,
						num: this.obj.num,
						remarks: this.remarks
					}
					uni.showLoading({
						title: "支付中"
					})
					exchangesubmit(data).then(res => {
						uni.hideLoading()
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 2000
						})
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							})
						}, 2000)
					})
				}else{
					uni.showToast({
						title:"您的积分不足",
						icon:"none",
						duration:2000
					})
				}
			}
		},
		onLoad(v) {
			this.id = v.id
			this.value = v.value
			this.siteobj = uni.getStorageSync("selectsite")
		},
		onShow() {
			uni.showLoading({
				title: "加载中"
			})
			exchange({
				id: this.id,
				num: this.value
			}).then(res => {
				uni.hideLoading()
				if (uni.getStorageSync("selectsite") != "") {
					this.siteobj = uni.getStorageSync("selectsite")
				} else {
					this.siteobj = res.data.address[0]
				}
				// 当没有地址时
				if (res.data.address.length == "") {
					this.show = false
					uni.showModal({
						title: "您还没有设置收货地址哦，赶快设置一个吧",
						success: function(res) {
							if (res.confirm) {
								that.jumpLink({
									link: "/pages/selectsite/index"
								})
							} else if (res.cancel) {
								uni.navigateBack({
									delta: 1
								})
							}
						}
					})
				}
				this.obj = res.data.commodity
				this.integral = res.data.integral
			})
		}
	}
</script>

<style scoped lang="scss">
	.topbox {
		background-color: #f42121;
		padding-top: 50rpx;
		box-sizing: border-box;
		position: fixed;
		top: 0;
		bottom: 0;
		right: 0;
		left: 0;

		.cont {
			position: fixed;
			background-color: #FFFFFF;
			top: 0;
			right: 25rpx;
			left: 25rpx;
			bottom: 0;
			height: 1406rpx;
			overflow: scroll;
		}

		.dzbox {
			background-color: #FFFFFF;
			// width: 700rpx;
			border-top-left-radius: 6rpx;
			border-top-right-radius: 6rpx;
			height: 166rpx;
			// margin-left: 25rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 45rpx 38rpx 36rpx 29rpx;
			box-sizing: border-box;
			margin-top: 13rpx;

			.namebox {
				display: flex;
				align-items: center;

				text {
					font-family: MicrosoftYaHei;
					font-size: 24rpx;
					color: #282828;
				}

				.name {
					font-family: MicrosoftYaHei-Bold;
					font-size: 28rpx;
					color: #333333;
					font-weight: 700;
					margin-right: 20rpx;
				}

				.moren {
					width: 57rpx;
					display: block;
					height: 26rpx;
					text-align: center;
					line-height: 26rpx;
					background-color: #FFE3AA;
					border-radius: 26rpx;
					font-size: 18rpx;
					font-family: Microsoft YaHei;
					color: #CC6600;
					margin-left: 20rpx;
				}
			}

			.site {
				font-family: MicrosoftYaHei;
				font-size: 24rpx;
				color: #282828;
				margin-top: 30rpx;
			}
		}

		.angle {
			width: 20rpx;
			height: 20rpx;
			border-top: 1px solid #000;
			border-left: 1px solid #000;
			transform: rotate(135deg)
		}
	}

	.boxs {
		background-color: #FFFFFF;
		padding-left: 10rpx;
		padding-right: 10rpx;
		padding-top: 32rpx;
		box-sizing: border-box;
		// width: 700rpx;
		border-bottom-left-radius: 6rpx;
		border-bottom-right-radius: 6rpx;

		.hr {
			width: 678rpx;
			height: 1rpx;
			background-color: #000000;
			opacity: 0.2;
			margin-top: 30rpx;
			margin-bottom: 40rpx;
		}

		.spxx {
			margin-left: 19rpx;
			display: flex;
			margin-top: 30rpx;
			margin-bottom: 30rpx;

			image {
				width: 181rpx;
				height: 181rpx;
			}

			.rightbox {
				margin-left: 18rpx;

				.namebox {
					display: flex;
					justify-content: space-between;

					.name {
						width: 397rpx;
						margin-right: 30rpx;
						line-height: 36rpx;
						font-family: MicrosoftYaHei;
						font-size: 24rpx;
						color: #000000;
					}

					.shulian {
						font-family: MicrosoftYaHei;
						font-size: 30rpx;
						color: #000000;
					}
				}

				.jifenbox {
					font-family: MicrosoftYaHei;
					font-size: 20rpx;
					color: #666666;
					margin-top: 40rpx;

					.num {
						font-family: PingFang-SC-Medium;
						font-size: 30rpx;
						color: #ff3333;
						margin-right: 20rpx;
					}
				}

				.jiegebox {
					display: flex;
					justify-content: space-between;
					margin-top: 35rpx;

					.ltbox {
						font-family: PingFang-SC-Medium;
						font-size: 18rpx;
						color: #ff3333;

						.qian {
							font-family: PingFang-SC-Medium;
							font-size: 30rpx;
							color: #ff3333;
						}
					}

					.rgtbox {
						font-family: PingFang-SC-Regular;
						font-size: 20rpx;
						color: #666666;
						margin-top: 20rpx;

						.qian {
							font-family: PingFang-SC-Medium;
							font-size: 30rpx;
							color: #ff3333;
						}
					}

				}

				.centerbox {
					font-family: MicrosoftYaHei;
					font-size: 20rpx;
					color: #666666;
					margin-top: 15rpx;
				}
			}
		}

		.smallbox {
			height: 100rpx;
		}
	}

	.hrs {
		height: 15rpx;
		background-color: #ededed;
	}

	.heji {
		display: flex;
		justify-content: space-between;
		font-family: PingFang-SC-Medium;
		font-size: 24rpx;
		color: #666666;
		margin-top: 50rpx;
		margin-left: 21rpx;
		margin-right: 21rpx;

		.hjname {
			font-family: MicrosoftYaHei;
			font-size: 24rpx;
			color: #000000;
			width: 96rpx;
		}

		textarea {
			margin-top: 6rpx;
			margin-left: 5rpx;
		}
	}

	.tijiaobox {
		display: flex;
		justify-content: space-between;
		position: fixed;
		bottom: 0;
		right: 0;
		left: 0;
		background-color: #FFFFFF;
		height: 100rpx;
		line-height: 100rpx;

		.fukuan {
			font-family: MicrosoftYaHei;
			font-size: 22rpx;
			color: #8b8b8b;
			margin-left: 45rpx;

			text {
				font-family: PingFang-SC-Bold;
				font-size: 32rpx;
				color: #e40000;
			}
		}

		.tijiao {
			width: 210rpx;
			height: 78rpx;
			background-color: #ff8400;
			border-radius: 39rpx;
			line-height: 78rpx;
			font-family: MicrosoftYaHei;
			font-size: 24rpx;
			color: #FFFFFF;
			text-align: center;
			margin-top: 15rpx;
			margin-right: 20rpx;
		}
	}

	// .yhqbox {
	// 	display: flex;
	// 	justify-content: space-between;
	// 	height: 100rpx;
	// 	line-height: 100rpx;

	// 	.yh {
	// 		font-family: MicrosoftYaHei;
	// 		font-size: 24rpx;
	// 		color: #000000;
	// 		margin-left: 29rpx;
	// 	}

	// 	.rightbox {
	// 		display: flex;
	// 		align-items: center;
	// 		margin-right: 20rpx;
	// 	}
	// }
</style>
